import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'
import TestMy from '@/myCharts/TestMy'

Vue.use(Router);

const requireComponent = require.context(
    "./../views/",
    true,
    /\.vue$/,
);

const { info } = console;

/**
 * 动态路由
 */
const autoRoutes = [];
requireComponent.keys().forEach(
    /**
     * @param {String} fileName 
     */
    function (fileName) {
        const p = fileName.substring(1, fileName.length - 4);
        autoRoutes.push({
            path: p,
            component: () => import('../views' + p + '.vue')
        });
        //显示一下组件的路径
        info("component path:",p);
    }
);

info(autoRoutes);

export default new Router({
    routes: [
        {
            path: '/',
            name: 'HelloWorld',
            component: HelloWorld
        },
        {
            path: '/testMy',
            name: 'testMy',
            component: TestMy
        }
    ].concat(autoRoutes)
})
